package com.um.jdy.platform.activity.controller;

import com.um.jdy.common.activity.entity.po.Discounts;
import com.um.jdy.common.activity.entity.vo.DiscountsVO;
import com.um.jdy.platform.activity.entity.dto.DiscountsPageDTO;
import com.um.jdy.platform.activity.entity.dto.SaveDiscountsDTO;
import com.um.jdy.platform.activity.manager.DiscountsManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 控制器：满减管理
 */
@RestController
@RequestMapping("/api/v1/cms/activity/discounts")
@Api(tags = "营销管理")
@ApiPermission("discounts")
@TokenRequired
public class DiscountsController extends BaseController<DiscountsManager> {

    @ApiPermission("page")
    @ApiOperation("分页查询满减活动")
    @PostMapping("/page")
    public Response<Page<Discounts>> getCouponsPage(@RequestBody DiscountsPageDTO params){
        return Response.success(manager.getPage(params.toPageParams()));
    }

    @ApiPermission("get")
    @ApiOperation(value = "详情")
    @GetMapping("/{id}")
    public Response<DiscountsVO> get(@ApiParam(value = "满减活动id") @PathVariable String id) {
        return Response.success(manager.get(id));
    }

    @ApiPermission("add")
    @ApiOperation(value = "新增满减活动")
    @PostMapping()
    public Response add(@RequestBody SaveDiscountsDTO saveDiscountsDTO){
        manager.addDiscounts(saveDiscountsDTO);
        return Response.success();
    }

    @ApiPermission("update")
    @ApiOperation(value = "修改满减活动")
    @PutMapping("{id}")
    public Response edit(@ApiParam(value = "满减活动id") @NotEmpty @PathVariable String id,
                         @RequestBody SaveDiscountsDTO saveDiscountsDTO){
        manager.editDiscounts(id, saveDiscountsDTO);
        return Response.success();
    }

    @ApiPermission("delete")
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

    @ApiPermission("delete_all")
    @ApiOperation("批量删除")
    @DeleteMapping
    public Response<Object> deleteIds(@ApiParam(value = "删除的id",required = true) @RequestBody List<String> ids) {
        return manager.deleteIds(ids);
    }

    @ApiPermission("edit_status")
    @ApiOperation(value = "修改活动状态")
    @PutMapping("status/{id}/{status}")
    public Response<DiscountsVO> editStatus(@ApiParam(value = "优惠券id") @NotEmpty @PathVariable String id,
                                          @ApiParam(value = "状态") @NotEmpty @PathVariable String status){
        return Response.success(manager.editStatus(id, status));
    }
}
